package dao.daoimp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import Exception.RegException;
import dao.RegDao;
import utils.ConnectionUtils;

public class RegDaoImp implements RegDao{


	public boolean Reg(String username, String pwd,
			String question,String answer)  throws RegException{
		Connection conn = null;
		PreparedStatement  psmt = null;
		ResultSet rs = null;
		String sql = "insert into t_user(tid,tname,tpwd,tquestion,tanswer) values(myseq.nextVal,?,?,?,?)";
		try {
			conn = ConnectionUtils.getConnection();
			psmt = conn.prepareStatement(sql);
			psmt.setString(1, username);
			psmt.setString(2, pwd);		
			psmt.setString(3, question);
			psmt.setString(4, answer);
			if( psmt.executeUpdate()!=0){
				return true;
			}
		} catch (Exception e) {
			// TODO: handle exception
		} finally{
			try {
				ConnectionUtils.close(conn, psmt, psmt, rs);				
			} catch (Exception e2) {
			}
		}
		return false;
	}	
}
